package com.linkme2night.adapters;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

import com.linkme2night.R;
import com.linkme2night.model.Venue;

public class SearchVenueListAdapter extends ArrayAdapter<Venue>{

    Context context; 
    int layoutResourceId;    
    Venue data[] = null;
    
    public SearchVenueListAdapter (Context context, int layoutResourceId, Venue[] data) {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        VenueHolder holder = null;
        
        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
            
            holder = new VenueHolder();
            holder.txt_venue = (TextView)row.findViewById(R.id.txtTitle);
            holder.rating = (RatingBar)row.findViewById(R.id.overall_rate);
      
            row.setTag(holder);
        }
        else
        {
            holder = (VenueHolder)row.getTag();
        }
        
        Venue venue = data[position];
        holder.txt_venue.setText(venue.getName());
        holder.rating.setRating(venue.getRanking());
        
        return row;
    }
    
    static class VenueHolder
    {
    	TextView txt_venue;
    	RatingBar rating;
    }
}